class Solution:

    def isInterleave(self, s1: str, s2: str, s3: str) -> bool:
        a, b, c = len(s1) + 1, len(s2) + 1, len(s3) + 1
        dp = [[[False] * c for _ in range(b)] for _ in range(a)]
        dp[0][0][0] = True
        for k in range(1, c):
            vc = s3[k - 1]
            for i in range(min(k, a - 1), 0, -1):
                if s1[i - 1] == vc and k - i >= 0 and k - i < b:
                    dp[i][k - i][k] = dp[i][k - i][k] or dp[i - 1][k - i][k - 1]
            for i in range(min(k, b - 1), 0, -1):
                if s2[i - 1] == vc and k - i >= 0 and k - i < a:
                    dp[k - i][i][k] = dp[k - i][i][k] or dp[k - i][i - 1][k - 1]
        return dp[a - 1][b - 1][c - 1]
